var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        code : '',
    },
    onLoad:function(options){
        var self = this;
        var zfid = options.zfid ? options.zfid : '';
        var code = options.agentcode ? options.agentcode : '';
        self.setData({
            options : options,
            code : code,
        });
        app.com.auth(function(user){
            app.com.http('agent','POST',{zfid:zfid,op:'join'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        Pagetheme : res.data.data.params.style,
                        params : res.data.data.params,
                        inited : true,
                    });
                }else{
                    app.com.alert(res.data.message);
                }
                wx.setNavigationBarTitle({
                  title:  '申请'+res.data.data.params.agentname,
                });
                
            });
        });
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.data.isdown = true;

        this.onLoad( this.data.options );
        this.data.isdown = false;

        wx.stopPullDownRefresh();
    },
    submit(e){
        var self = this;
        var postdata = {
            op : 'subjoin',
            name : self.data.name,
            tel : self.data.tel,
            address : self.data.address,
            code : self.data.code,
        };
        if( postdata.name == '' ){
            app.com.alert('请填写姓名');
            return false;
        }
        if( postdata.tel == '' ){
            app.com.alert('请填写电话');
            return false;
        }
        if( !postdata.address ){
            app.com.alert('请选择地区');
            return false;
        }

        app.com.http('agent','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno && res.data ) {
                app.com.alert(res.data.message,function(){
                    wx.navigateBack({delta:2});
                });
            }else{
                app.com.alert(res.data.message);
            }
        });

    },
    name(e){
        this.setData({
            name : e.detail.value,
        });
    },
    tel(e){
        this.setData({
            tel : e.detail.value,
        });
    },
    codefn(e){
        this.setData({
            code : e.detail.value,
        });
    },
    bindRegionChange : function(e){
        var self = this;
        self.setData({
            address : e.detail.value[0] +','+e.detail.value[1] +','+e.detail.value[2]
        })
    },
    selectarea(){
        this.selectComponent('#ausarea').show();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
    FormIdsubmit : function(e){
        if( app.globalData.formarr.length <= 20 ) app.globalData.formarr.push(e.detail.formId);
    }

})